<template>
  <div class="addform">
    <h1>修改成员表</h1>
    <br />
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="120px"
      class="demo-ruleForm"
    >
      <el-form-item label="专家姓名" prop="zjbName">
        <el-input v-model="ruleForm.zjbName"></el-input>
      </el-form-item>
      <el-form-item label="专家职业" prop="zjbName">
        <el-input v-model="ruleForm.zjbPos"></el-input>
      </el-form-item>
      <el-form-item label="专家头像" prop="zjbImg">
        <el-upload
          style="float: left"
          action=""
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
          :limit="1"
        >
          <i class="el-icon-plus"></i>
          <div slot="tip" class="el-upload__tip">
            只能上传jpg/png文件，且不超过500kb,只能上传一张
          </div>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >修改专家</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>

    <el-dialog
      title="温馨提示"
      :visible.sync="successVisible"
      width="18%"
    >
      <el-button
        type="success"
        icon="el-icon-check"
        circle
        @click="successVisible = false"
      ></el-button>
      <h2 style="color: green">修改成功</h2>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fileList: [{ name: "food.jpeg", url: "" }],
      dialogImageUrl: "",
      dialogVisible: false,
      ruleForm: {//保证前后端名称相同
        zjbName: "",
        zjbImg: "",
        zjbPos: ""
      },//如果没输入的提示信息
      rules: {
        zjbName: [
          { required: true, message: "请输入专家的名称", trigger: "blur" },
        ],
        zjbPos: [
          { required: true, message: "请输入专家的职业", trigger: "blur" },
        ]
      },
      successVisible: false,
    };
  },
     created() {// 提交方法 先判断提交表单是否有空=>validate
    const _this = this;
    console.log(_this.$route.params.Id)
    this.axios({
      method: "get",
      url: _this.baseUrl()+"/queryZjb/"+_this.$route.params.Id,
    }).then(function (resp) {
      console.log(resp.data);
      _this.ruleForm=resp.data
    });
  },
  methods: {
    // 提交方法 先判断提交表单是否有空=>validate
        submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 由于axios内部必须使用_this才能使用this
          const _this = this;
          this.axios({
            method: "post",
            url: _this.baseUrl() + "editZjb",
            //传递给后端的数据
            data: _this.ruleForm
          }).then(function (resp) {
            console.log(resp.data);
            _this.successVisible = true;//提交成功提示
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //清空表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //删除图片
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    //图片显示
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang="less">
.addform {
  width: 800px;
  margin: 0 auto;
  .xx {
    float: left;
  }
}
@media screen and (max-width: 767px) {
  .addform {
    width: 100%;
  }
}
</style>